package org.studiox.graph.persistence.mybatis.dao;

import org.apache.ibatis.annotations.*;
import org.studiox.graph.persistence.model.GraphVertexDO;

import java.util.List;

public interface GraphVertexDao {

  @Select("select * from graph_vertex")
  @Results(
      id = "graphVertexDOMap",
      value = {
        @Result(id = true, column = "id", property = "id"),
        @Result(column = "uniq", property = "uniq"),
        @Result(column = "type", property = "type"),
        @Result(column = "owner", property = "owner"),
        @Result(column = "janus_vertex_id", property = "janusVertexId"),
        @Result(column = "neo4j_vertex_id", property = "neo4jVertexId"),
        @Result(column = "nebula_vertex_id", property = "nebulaVertexId"),
        @Result(column = "temp", property = "temp"),
        @Result(column = "deleted", property = "deleted"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
      })
  List<GraphVertexDO> findAll();

  @Insert(
      "insert into graph_vertex(uniq,type,owner,janus_vertex_id,temp) "
          + "values (#{uniq},#{type},#{owner},#{janusVertexId},#{temp})")
  void save(GraphVertexDO graphVertexDO);

  @Update(
      "update graph_vertex set uniq=#{uniq},type=#{type},owner=#{owner},janus_vertex_id=#{janusVertexId},"
          + "temp=#{temp},deleted=#{deleted},update_time=#{updateTime} where id=#{id}")
  void update(GraphVertexDO graphVertexDO);

  @Delete("delete from graph_vertex where id=#{id}")
  void delete(@Param("id") Long id);

  @Select("select * from graph_vertex where id=#{id}")
  GraphVertexDO findById(@Param("id") Long id);

  @Select("select count(*) from graph_vertex")
  int findTotalNum();
}
